#!/bin/sh

for i in /etc/my.cnf /etc/my.cnf.d/server.cnf ; do
	if [ -f ${i} ] ; then
		if [ "$(grep 'innodb_use_native_aio' ${i})" == "" ] ; then
			sed -i -e's|\[mysqld\]|\[mysqld\]\n#OpenVZ AIO bug fix\ninnodb_use_native_aio=0|g' ${i}
			echo "Add 'innodb_use_native_aio=0' to ${i}"
		else
			echo "Already exist 'innodb_use_native_aio' in ${i}"
		fi

		if [ "$(grep 'skip-innodb' ${i})" == "" ] ; then
			sed -i -e's|\[mysqld\]|\[mysqld\]\nskip-innodb|g' ${i}
			echo "Add 'skip-innodb' to ${i}"
		else
			echo "Already exist 'skip-innodb' in ${i}"
		fi

		if [ "$(grep 'default-storage-engine' ${i})" == "" ] ; then
			sed -i -e's|\[mysqld\]|\[mysqld\]\ndefault-storage-engine=myisam|g' ${i}
			echo "Add 'default-storage-engine=myisam' to ${i}"
		else
			echo "Already exist 'default-storage-engine=myisam' in ${i}"
		fi

		if [ "$(grep 'performance_schema' ${i})" == "" ] ; then
			sed -i -e's|\[mysqld\]|\[mysqld\]\nperformance_schema=on|g' ${i}
			echo "Add 'performance_schema=on' to ${i}"
		else
			echo "Already exist 'performance_schema=on' in ${i}"
		fi
	fi
done


